import { BaseEntity } from '../../base/entity/base';
import { Column, Entity, Index } from 'typeorm';

/**
 * 支付模块-支付记录表
 */
@Entity('pay_payment')
export class PayPaymentEntity extends BaseEntity {
  @Index()
  @Column({ comment: '用户ID' })
  userId: number;

  @Index()
  @Column({ comment: '订单ID' })
  orderId: number;

  @Index({ unique: true })
  @Column({ comment: '支付流水号', length: 32 })
  paymentNo: string;

  @Column({ comment: '第三方支付流水号', length: 64, nullable: true })
  thirdPartyNo: string;

  @Column({ comment: '支付金额', type: 'decimal', precision: 10, scale: 2 })
  amount: number;

  @Column({
    comment: '支付方式',
    dict: ['微信支付', '支付宝', '余额支付', '银行卡'],
    default: 0,
  })
  paymentMethod: number;

  @Column({
    comment: '支付状态',
    dict: ['待支付', '支付中', '支付成功', '支付失败', '已退款'],
    default: 0,
  })
  status: number;

  @Column({ comment: '支付时间', nullable: true })
  payTime: Date;

  @Column({ comment: '支付完成时间', nullable: true })
  completeTime: Date;

  @Column({ comment: '退款时间', nullable: true })
  refundTime: Date;

  @Column({ comment: '退款金额', type: 'decimal', precision: 10, scale: 2, nullable: true })
  refundAmount: number;

  @Column({ comment: '支付渠道', length: 50, nullable: true })
  payChannel: string;

  @Column({ comment: '支付IP', length: 45, nullable: true })
  payIp: string;

  @Column({ comment: '支付设备信息', type: 'json', nullable: true })
  deviceInfo: any;

  @Column({ comment: '第三方返回信息', type: 'json', nullable: true })
  thirdPartyResponse: any;

  @Column({ comment: '失败原因', type: 'text', nullable: true })
  failReason: string;

  @Column({ comment: '备注', type: 'text', nullable: true })
  remark: string;

  // 余额支付相关字段
  @Column({ comment: '支付前余额', type: 'decimal', precision: 10, scale: 2, nullable: true })
  beforeBalance: number;

  @Column({ comment: '支付后余额', type: 'decimal', precision: 10, scale: 2, nullable: true })
  afterBalance: number;
}